<?php
/**
 * @Notes:【】
 * @Date: 2022-06-16 23:10
 */

namespace App\WsService\Message;

use App\Service\WebSocket\SocketClientService;
use App\WsService\ClientService;
use Hyperf\Di\Annotation\Inject;

abstract class BaseService
{
    /**
     * @Inject()
     * @var ClientService
     */
    protected $clientService;


    private function toJson(string $event, $data): string
    {
        return json_encode(["event" => $event, "content" => $data]);
    }

    public function sendFd($fd, $event, $message)
    {
        $this->clientService->sendFdsMessage($fd, $this->toJson($event, $message));
    }

    public function sendUser($userId, $event, $message)
    {
        $this->clientService->sendUserMessage($userId, $this->toJson($event, $message));
    }
}